#ifndef __SERVER_BROADCASTER__
#define __SERVER_BROADCASTER__

#include <deque>
#include <windows.h>
#include <cassert>

#include "..\Common\CommonMessage.h"
#include "..\Common\CommonObject.h"

#include "ServerBase.h"
#include "ServerClientManager.h"



class broadcaster {
private:	
	typedef std::deque<pair<BRODCAST_MESSAGE, broadcast_msg_base*>> msg_deque;	

	msg_deque			m_MessageDeque;
	server_base*		m_pServer;	
	client_manager*		m_pClientManager;
	CRITICAL_SECTION	m_CriticalSection;
	HANDLE				m_SendEvent;

	void PopMessage(void);

public:
	broadcaster(void);
	~broadcaster(void);

	void LinkServer(server_base* pServer);
	void LinkClient(client_manager* pClientManager);

	void PushMessageNewClient(const ip& IP, const unsigned int& ClientCode, const unsigned int&	UdpPort);
	void PushMessageOffClient(const unsigned int& ClientCode);
	void PushMessageNewObject(const unsigned int& ObjectID, const OBJECT_TYPE& ObjectType, const unsigned int& OwnerCode, 
								const unsigned int& ExtraLength, char* ExtraPtr);
	void PushMessageDelObject(const unsigned int& ObjectID);
	void PushMessageMessage(const unsigned int& MsgLength, char* MsgString);	
	void PushMessageCheckSocket(void);
	void PushMessageMissileCrush(const unsigned int& MissileOwner, const unsigned int& MissileID, const unsigned int& TargetClient); 

	void Send(void);	// send deque's top message.	
};


#endif